<template>
  <div class="form">
      <el-form label-position="top" label-width="80px" :model="menuForm">
      <el-form-item label="编号">
        <el-input v-model="menuForm.code"></el-input>
      </el-form-item>
      <el-form-item label="昵称">
        <el-input v-model="menuForm.nameNick"></el-input>
      </el-form-item>
      <el-form-item label="中文姓名">
        <el-input v-model="menuForm.nameZh"></el-input>
      </el-form-item>
      <el-form-item label="英文姓名">
        <el-input v-model="menuForm.nameEn"></el-input>
      </el-form-item>
      <el-form-item label="性别">
        <el-input v-model="menuForm.gender"></el-input>
      </el-form-item>
      <el-form-item label="身份证号码">
        <el-input v-model="menuForm.idCard"></el-input>
      </el-form-item>
      <el-form-item label="手机号码">
        <el-input v-model="menuForm.phoneNumber"></el-input>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="menuForm.email"></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="menuForm.description"></el-input>
      </el-form-item>
      <el-form-item label="角色">
        <el-input v-model="menuForm.role"></el-input>
      </el-form-item>
      <el-form-item label="是否禁用">
        <el-switch
          v-model="menuForm.disabled"
          active-value="1"
          inactive-value="0">
        </el-switch>
      </el-form-item>
      <div style="text-align: right;">
        <el-form-item>
          <el-button type="primary" @click="onUpdate">保存</el-button>
          <el-button @click="onClose">取消</el-button>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>

<script>
import api from '@/api'

export default {
  name: 'sys-user-edit',
  props: {
    id: {
      type: Number
    }
  },
  data () {
    return {
      menuForm: {
      }
    }
  },
  mounted () {
    this.getById()
  },
  methods: {
    onUpdate () {
      var param = this.menuForm
      api.sysUser.sysUserUpdateById(param).then(res => {
        this.$message({ type: 'info', message: '已更新' })
        this.onClose()
        this.$emit('refresh')
      })
    },
    getById () {
      if (this.id === 0 || !this.id) {
        return
      }
      var param = { id: this.id }
      api.sysUser.sysUserFindById(param).then(res => {
        this.menuForm = res
      })
    },
    onClose () {
      this.$emit('closeDrawer')
    }
  }
}
</script>

<style lang="scss">
  .form {
    padding: 10px;
  }
</style>
